package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.dto.QuerySampleDTO;
import top.hcode.hoj.pojo.entity.{{properCase name}};
import top.hcode.hoj.service.admin.Admin{{properCase name}}Service;

/**
 * @author orangej
 * @since {{today}}
 */
@Slf4j
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class Admin{{properCase name}}Controller {

    private final Admin{{properCase name}}Service {{camelCase name}}Service;

    @GetMapping("/admin/{{dashCase name}}/list")
    public CommonResult<IPage<{{properCase name}}>> get{{properCase name}}List(QuerySampleDTO querySampleDTO) {
        return CommonResult.successResponse({{camelCase name}}Service.get{{properCase name}}List(querySampleDTO));
    }

    @PostMapping("/admin/{{dashCase name}}/save")
    public CommonResult<{{properCase name}}> save{{properCase name}}(@RequestBody {{properCase name}} {{camelCase name}}) {
        return CommonResult.successResponse({{camelCase name}}Service.save{{properCase name}}({{camelCase name}}));
    }

    @PostMapping("/admin/{{dashCase name}}/delete")
    public CommonResult<Void> delete{{properCase name}}(@RequestBody BaseIdDTO dto) {
        {{camelCase name}}Service.delete{{properCase name}}(dto.getId());
        return CommonResult.successResponse();
    }

}
